<template>
  <view class="setPassword">
    <u-form :model="form" ref="uForm">
      <!--<u-form-item label="当前密码" prop="oldPassword" label-width="150rpx">
        <view class="input_item">
          <u-input v-model="from.oldPassword" type="number" maxlength="11" :border="false" placeholder="请输入当前密码" />
        </view>
      </u-form-item>-->
      <u-form-item label="新的密码"  label-width="150rpx">
        <view class="input_item">
          <u-input v-model="from.newsPassword" type="password" :border="false" placeholder="请输入新的密码" />
        </view>
      </u-form-item>
      <u-form-item label="确认密码"  label-width="150rpx">
        <view class="input_item">
          <u-input v-model="from.confirmPassword" type="password" :border="false" placeholder="请输入确认密码" />
        </view>
      </u-form-item>
    </u-form>
    <view class="lijipay">
      <u-button hover-class="none" type="primary" shape="circle" :ripple="false" :disabled="disabled" :loading="Payloading" @click="setPassword()">确定
      </u-button>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      from: {
        newsPassword: '',
        confirmPassword: ''
      },
      type: '', // 3:修改取款密码 5:修改登录密码
      userInfo: {},
    };
  },
  onLoad(options) {
    console.log('options', options)
    this.type = options.type

  },
  methods: {

    setPassword() {
      let that = this
      if (that.from.newsPassword == '') {
        uni.showToast({
          title: '请输入密码',
          icon: 'none',
          duration: 2000
        })
      } else if (that.from.confirmPassword == '') {
        uni.showToast({
          title: '请确认密码',
          icon: 'none',
          duration: 2000
        })
      } else {

        if (that.from.newsPassword != that.from.confirmPassword){
          uni.showToast({
            title: '两次密码不一致，请重新输入',
            icon: 'none',
            duration: 2000
          })
          setTimeout(()=>{
            this.from.newsPassword = ''
            this.from.confirmPassword = ''
          },2000)
        }else {
          //console.log('密码==',that.from)
          if (that.type == 3){//提现密码接口
            that.$api.GetUpdateCashPasswordAPI({
              cash_password: that.from.newsPassword,
              re_cash_password: that.from.confirmPassword
            }).then(res => {
              if (res){
                uni.showToast({
                  title: '提现密码修改成功！',
                  icon: 'none',
                  duration: 2000
                })
                this.GetUserInfo()
                setTimeout(()=>{
                  uni.navigateBack()
                },2000)
              }
            }).catch(err => {
              uni.showToast({
                title: err.data.msg,
                icon: 'none',
                duration: 2000
              });
            })
          }else if (that.type == 5){ //登录密码接口
            that.$api.GetUpdatePasswordAPI({
              new_password: that.from.newsPassword,
              re_password: that.from.confirmPassword
            }).then(res => {
              if (res){
                uni.showToast({
                  title: '登录密码修改成功！',
                  icon: 'none',
                  duration: 2000
                })
                setTimeout(()=>{
                  uni.clearStorageSync();
                  uni.removeStorageSync('userinfo');
                  uni.removeStorageSync('token');
                  uni.reLaunch({
                    url: '/pages/logon/logon'
                  });
                },2000)
              }
            }).catch(err => {
              uni.showToast({
                title: err.data.msg,
                icon: 'none',
                duration: 2000
              });
            })
          }
        }
      }
    },
    //获取用户信息
    GetUserInfo() {
      let that = this
      that.$u.post('/shop/user/info', {

      }).then(res => {
        console.log('账号信息', res)
        that.userInfo = res.result
        uni.setStorageSync('userinfo', res.result)
      }).catch(err => {

      });
    },
  }
}
</script>

<style lang="scss">
  .setPassword {
    padding: 30rpx 30rpx;
    .u-border-bottom:after{border-bottom-width: 0}
    .nowphone {
      font-weight: bold;
      font-size: 34rpx;
    }

    .input_item {
      border-radius: 200rpx;
      background-color: #f9f9f9;
      padding: 20rpx 40rpx;
      margin: 30rpx 0;
      position: relative;
      display: flex;
      align-items: center;

      u-input {
        flex: 1;
      }

      .getCode {
        //position: absolute;
        right: 0;
        top: 0;
        color: #0084FF;
      }
    }
  }
  .lijipay {
    width: 90%;
    margin-top: 100rpx;
    position: fixed;
    left: 0;
    right: 0;
    margin: 0 auto;
    bottom: 2%;

    .u-size-default {
      height: 80rpx !important;
      line-height: 80rpx !important;
      background-image: linear-gradient(to right, #FE9400, #FF3D22);
      color: #fff;
    }
  }
</style>
